
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>
#include <string.h>
#include <poll.h>
#include <signal.h>

static int fd;

/*
 * ./dht11_test /dev/dht11
 *
 */
int main(int argc, char **argv)
{
 
	struct pollfd fds[1];
	int timeout_ms = 5000;
	int ret;
	int	flags;
	char buf[2];/* support negative datas*/

	int i;
	
	/* 1. 判断参数 */
	if (argc != 2) 
	{
		printf("Usage: %s <dev>\n", argv[0]);
		return -1;
	}


	/* 2. 打开文件 */
	fd = open(argv[1], O_RDWR | O_NONBLOCK);
	if (fd == -1)
	{
		printf("can not open file %s\n", argv[1]);
		return -1;
	}

	while (1)
	{
		ret = read(fd, buf, 2);
		printf("ret:%d\n", ret);
		if (ret == 2)
			printf("Humodity = %d\nTemperature = %d\n", buf[0], buf[1]);
		else
		{
			printf("data err\n");
			perror("read");
		}
		sleep(3);
	}
	close(fd);
	return 0;
}


